//
//  PlusController.m
//  Budejie
//
//  Created by 远成物流 on 2017/5/15.
//  Copyright © 2017年 陈梦佳. All rights reserved.
//

#import "PlusController.h"
#import "PlaceholderTextView.h"
#import "SelectImageView.h"
#import <TZImagePickerController/TZImagePickerController.h>

@interface PlusController ()<UITextViewDelegate>

@property(nonatomic,strong)PlaceholderTextView *textView;
@property(nonatomic,strong)SelectImageView *selectImageView;

@end

@implementation PlusController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationController.navigationBar.tintColor = [UIColor redColor];
    self.automaticallyAdjustsScrollViewInsets = YES;
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancel:)];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"发送" style:UIBarButtonItemStylePlain target:self action:@selector(send:)];
    
    //添加输入控件
    [self addInputView];
}

-(void)cancel:(UIButton *)button{
    [self dismissViewControllerAnimated:YES completion:nil];
}

-(void)send:(UIButton *)button{
    
}

-(void)addInputView{
    PlaceholderTextView *textV = [[PlaceholderTextView alloc] initWithFrame:CGRectMake(B_Margin, B_Margin, ScreenW-2*B_Margin, 200)];
    textV.delegate = self;
    textV.font = [UIFont systemFontOfSize:15];
    textV.placeholder = @"分享新鲜事...";
    textV.returnKeyType = UIReturnKeySend;
    [self.view addSubview:textV];
    self.textView = textV;
    
    //监听输入框文字改变
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChange) name:UITextViewTextDidChangeNotification object:textV];
    
    //添加图片
    SelectImageView *select = [[SelectImageView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(textV.frame), ScreenW, 100)];
    select.controller = self;
    [self.view addSubview:select];
    self.selectImageView = select;
}

//输入框文字变化时触发
-(void)textChange{
    
    //行距
//    NSMutableParagraphStyle* defaultStyle= [[NSMutableParagraphStyle alloc]init];
//    defaultStyle.lineBreakMode = NSLineBreakByWordWrapping;
//    defaultStyle.lineSpacing += 1.5;
//    
//    CGSize textSize = CGSizeMake(ScreenW-2*B_Margin, MAXFLOAT);
//    CGFloat height = ceil([self.textView.text boundingRectWithSize:textSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15],NSParagraphStyleAttributeName:defaultStyle} context:nil].size.height)+1;
//    
//    self.textView.height_sd = height;
//    self.selectImageView.top_sd = CGRectGetMaxY(self.textView.frame);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
